package com.xzr.hospitalregister.view;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.xzr.hospitalregister.R;
import com.xzr.hospitalregister.adapter.AdapterDialogLastestVersionAppRemindContent;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/2/2.
 */

public class DialogLastestVersionAppRemind extends DialogFragment implements View.OnClickListener {
    private RecyclerView updateContentRV;
    private TextView updapte, notUpdate;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.dialog_lastest_version_app_remind, null);
        initWidget(inflate);
        initData();
        return inflate;
    }

    public void initWidget(View view) {
        updateContentRV = (RecyclerView) view.findViewById(R.id.rv_dialog_lastest_version_app_remind_updateContent);
        updapte = (TextView) view.findViewById(R.id.tv_dialog_lastest_version_app_remind_update);
        updapte.setOnClickListener(this);
        notUpdate = (TextView) view.findViewById(R.id.tv_dialog_lastest_version_app_remind_notUpdate);
        notUpdate.setOnClickListener(this);
    }

    public void initData() {
        List<String> updateContent = new ArrayList<>();
        JsonObject versionInfoJson = (JsonObject) new JsonParser().parse(getArguments().getString("versionInfo"));
        Log.e("TAG", "获取versionInfo+++" + getArguments().getString("versionInfo"));
//        JsonArray jsonArray = (JsonArray) versionInfoJson.get("updateContent");
//
//        for (int i = 0; i < jsonArray.size(); i++) {
//            updateContent.add(jsonArray.get(i).getAsJsonObject().get("updateContentDetail").getAsString());
//        }
        AdapterDialogLastestVersionAppRemindContent adapter = new AdapterDialogLastestVersionAppRemindContent(updateContent, getActivity());
        updateContentRV.setLayoutManager(new LinearLayoutManager(getActivity()));
        updateContentRV.setAdapter(adapter);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_dialog_lastest_version_app_remind_notUpdate:

                this.getDialog().dismiss();
                break;
            case R.id.tv_dialog_lastest_version_app_remind_update:
                DialogLastestVersionAppDownload dialogLastestVersionAppDownload = new DialogLastestVersionAppDownload();
                dialogLastestVersionAppDownload.setCancelable(false);
                dialogLastestVersionAppDownload.show(getActivity().getSupportFragmentManager(), "DialogLastestVersionAppDownload");
                this.getDialog().dismiss();
                break;
        }

    }
}
